﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LaughingDog.GameObjects;
using Microsoft.Xna.Framework;

namespace LaughingDog.Components.Shapes
{
    public class CircleShape : Shape
    {
        private Single mRadius;
        private Single mNumberOfSides = 15;

        public Single Radius { get { return mRadius; } set { mRadius = value; Create(); } }
        public Single NumberOfSides { get { return mNumberOfSides; } set { mNumberOfSides = value; Create(); } }

        public CircleShape(GameObject gameObject)
            : base(gameObject)
        {
        }

        private void Create()
        {
            ClearVectors();

            Single max = 2 * (Single)Math.PI;
            Single step = max / (Single)mNumberOfSides;

            for (Single theta = 0; theta < max; theta += step)
            {                
                AddVector(new Vector2(mRadius * (Single)Math.Cos((Double)theta), mRadius * (Single)Math.Sin((Double)theta)));
            }

            // then add the first vector again so it's a complete loop
            AddVector(new Vector2(mRadius * (Single)Math.Cos(0), mRadius * (Single)Math.Sin(0)));
        }
    }
}
